package com.buaa.contentProvider;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.test.AndroidTestCase;
import android.util.Log;

/**
 * Created by Administrator on 2016/4/23.
 */
public class MyTest extends AndroidTestCase {
    public MyTest(){}
    public void insert(){
        ContentResolver contentResolver=getContext().getContentResolver();
        Uri uri=Uri.parse("content://com.buaa.contentprovider.StudentProvider/student");
        ContentValues values=new ContentValues();
        values.put("name","张三");
        values.put("address","南京");
        contentResolver.insert(uri,values);
    }

    public void delete(){
        ContentResolver contentResolver=getContext().getContentResolver();
        Uri uri=Uri.parse("content://com.buaa.contentprovider.StudentProvider/student/1");
        contentResolver.delete(uri,null,null);
    }

    public void update(){
        ContentResolver contentResolver=getContext().getContentResolver();
        Uri uri=Uri.parse("content://com.buaa.contentprovider.StudentProvider/student/1");
        ContentValues values=new ContentValues();
        values.put("name","孙国库");
        values.put("address","咸阳");
        contentResolver.update(uri,values,null,null);
    }

    public void query(){
        ContentResolver contentResolver=getContext().getContentResolver();
        Uri uri=Uri.parse("content://com.buaa.contentprovider.StudentProvider/student");
        Cursor cursor=contentResolver.query(uri,null,null,null,null);
        while (cursor.moveToNext()){
            Log.i("sgk","name"+cursor.getString(cursor.getColumnIndex("name"))+"-------address"+cursor.getString(cursor.getColumnIndex("address")));
        }
    }
}
